<?php
/**
 * Created by PhpStorm.
 * User: lzy
 * Date: 2018/11/27
 * Time: 15:51
 */

namespace App\FreeBird\Controllers\Home;

use App\Base\Controllers\Controller;
use App\FreeBird\Models\MessageModel;
use Illuminate\Http\Request;

class MessageController extends Controller
{
    /**
     * @return MessageModel
     */
    public function getMessageModel()
    {
        return app()->make(MessageModel::class);
    }

    public function getMessageLit(Request $request)
    {
        $limit = empty($request->input("limit")) ? 10 : $request->input("limit");
        $sort = empty($request->input("sort")) ? 'create_time' : $request->input("sort");
        $order = empty($request->input("order")) ? 'desc' : $request->input("order");
        $where=function ($query){
          $query->where("uid",AUID);
        };
      return $this->getMessageModel()->newQuery()->where($where)->orderBy($sort, $order)->paginate($limit);
    }

    public function getMessageDetail(Request $request)
    {
        $where=function ($query)use ($request){
            $query->where("uid",AUID);
            $query->where("id",$request->input("id"));
        };
        return $this->getMessageModel()->newQuery()->where($where)->first();
    }
}